import { Component, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { Body, _HttpClient } from '@delon/theme';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import { ACLService } from '@delon/acl';
import { STData } from '@delon/abc';
import { OperationPersonAddComponent } from '../operation-person-add/operation-person-add.component';

@Component({
  selector: 'app-operation-person-list',
  templateUrl: './operation-person-list.component.html',
  styles: []
})
export class OperationPersonListComponent implements OnInit {
  @ViewChild('st', { static: false }) st: TablePageComponent;
  selectData: any;
  loading = false;
  addUserInfo = {
    userAccount: '',
    userPassword: '',
    userName: '',
    roles: [],
    depts: []
  };
  config: SPage = {
    columns: [
      {
        index: 'userName',
        title: '账号',
      },
      {
        index: 'type',
        title: '人员类型',
        type:ColumnType.tag,
        tag:{
          1:{text: '运维管理人员'},
          2:{text: '物业人员'}
        },
        filter: {
          placeholder: '请选择人员类型',
          type: 'select',
          items:[
            {label:"运维管理人员",value:1},
            {label:"物业人员",value:2}
          ]
        }
      },
      {
        index: 'status',
        title: '状态',
        type:ColumnType.tag,
        tag:{
          true:{text:"正常",color:"green"},
          false:{text:"禁用",color:"red"}
        },
        filter: {
          placeholder: '请选择状态',
          type: 'select',
          items:[
            {label:"正常",value:true},
            {label:"禁用",value:false}
          ]
        }
      },
      {
        index: 'createPeople',
        title: '创建人',
        filter: {
          placeholder: '创建人',
          type: 'string'
        }
      },
      {
        index: 'createTime',
        title: '创建时间',
        filter: {
          placeholder: '创建时间',
          type: 'date'
        }
      },
      {
        index: '',
        title: '操作',
        fixed:'right',
        buttons:[
          {
            text:'编辑',
            click:(_record)=>{
              this.editDic(_record)
            }
          },
          {
            text:'删除',
            click:(_record)=>{
              this.deleteDic(_record)
            }
          },
        ]
      },
    ],
    showCheckBox: false,
    reqUrl:'/core/qr/manager/page',
    defaultParam:{order: "createTime desc",status:true}
  }
  constructor(private http: _HttpClient,  private api: ApiService, private modal: NzModalService, private message: NzMessageService, private aclService: ACLService) { }
  
  ngOnInit() {

  }

  // 编辑功能开始
  editDic( _param?: object): void {
    const type = 1
    const modal = this.modal.create({
      nzTitle: "编辑",
      nzContent: OperationPersonAddComponent,
      nzWidth: 1300,
      nzComponentParams: {
        type,
        _param
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
    modal.afterClose.subscribe(res => {
      if (res === 'ok') {
        this.st.reload();
      }
    })
  }

  _console(e: any): void {
    this.selectData = e;
  }
  dataProcess(data: STData[]){
    return data;
  }

  //删除
  deleteDic(param): void {
    this.modal.confirm({
      nzTitle: '确定删除?',
      nzOnOk: () => {
        
        this.http.request("get","/core/qr/manager/delete",{params:{id:param.id}}).subscribe((res:any) => {
          if (res.status === '200') {
            this.message.success('删除成功');
            this.st.reload();
          }else{
            this.message.error(res.message)
          }
        })
      }
    })
  }
 
 
  //新增运维人员
  addPerson(){
    const type = 0
    const modal = this.modal.create({
      nzTitle: "新增",
      nzContent: OperationPersonAddComponent,
      nzWidth: 1300,
      nzComponentParams: {
        type
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
  }
}
